﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.VungKhuvuc
{
    public partial class popSuaDHtong : Form
    {
        private Int16 iddht = -1;
        public popSuaDHtong(Int16 id)
        {
            InitializeComponent();
            iddht = id;
        }

        private void popSuaDHtong_Load(object sender, EventArgs e)
        {
            List<trangthai> list = new List<trangthai>();
            trangthai ls = null;

            ls = new trangthai();
            ls.name = "Hoạt động";
            ls.value = "1";
            list.Add(ls);

            ls = new trangthai();
            ls.name = "Không hoạt động";
            ls.value = "0";
            list.Add(ls);

            cbtrangthai.DataSource = list;
            cbtrangthai.DisplayMember = "name";
            cbtrangthai.ValueMember = "value";
            //
            adminDHtong addht = new adminDHtong();
            DataTable dtdht = addht.chitiet(iddht);
            if (dtdht != null && dtdht.Rows.Count > 0)
            {
                txttendh.Text = dtdht.Rows[0]["tenDHTong"].ToString();
                txtmota.Text = dtdht.Rows[0]["mota"].ToString();
            }
        }
        // khai báo 1 hàm delegate
        public delegate void SuaDHT(int outid);
        // khai báo 1 kiểu hàm delegate
        public SuaDHT MyFunction;
        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyFunction != null)
            {// tại đây gọi nó
                string tendht = txttendh.Text.Trim();
                string mota = txtmota.Text.Trim();
                Int16 trangthai = Int16.Parse((cbtrangthai.SelectedValue == null) ? "0" : cbtrangthai.SelectedValue.ToString());
                adminDHtong addht = new adminDHtong();
                int outid = addht.sua(iddht, tendht, mota, trangthai);
                MyFunction(outid);
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
